<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>shopcat</title>
    <script src="Vue/vue.js"></script>
    <script src="Vue/vue-router.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        table {
            margin: 0 auto;
            border-collapse: collapse;
        }

        tr {

        }

        td {
            width: 200px;
            height: 50px;
            text-align: center;
            border: 1px solid gainsboro;
        }

        .price {
            width: 1004px;
            height: 40px;
        }

        button {
            width: 20px;
            height: 20px;
        }
    </style>
</head>
<body>
<div id="cat">
    <table>
        <tr>
            <td>编号</td>
            <td>名称</td>
            <td>单价</td>
            <td>数量</td>
            <td>总价</td>
        </tr>
        <tr>
            <td>1</td>
            <td>apple</td>
            <td>3</td>
            <td>
                <button @click="applereduce">-</button>
                {{applenum}}
                <button @click="appleadd">+</button>
            </td>
            <td>{{appletotal}}</td>
        </tr>
        <tr>
            <td>2</td>
            <td>pear</td>
            <td>4</td>
            <td>
                <button @click="pearreduce">-</button>
                {{pearnum}}
                <button @click="pearadd">+</button>
            </td>
            <td>{{peartotal}}</td>
        </tr>
        <tr>
            <td>3</td>
            <td>banana</td>
            <td>5</td>
            <td>
                <button @click="bananareduce">-</button>
                {{banananum}}
                <button @click="bananaadd">+</button>
            </td>
            <td>{{bananatotal}}</td>
        </tr>
    </table>
    <table>
        <tr>
            <td class="price">总价：￥{{price}}</td>
        </tr>
    </table>
</div>
<script>
    var vue = new Vue({
        el: "#cat",
        data: {
            applenum: 0,
            appletotal: 0,
            pearnum: 0,
            peartotal: 0,
            banananum: 0,
            bananatotal: 0,
            // price: 0,
        },
        methods: {
            appleadd: function () {
                this.applenum++;
                this.appletotal = this.applenum * 3;

            },
            applereduce() {
                if (this.applenum == 0) {
                    this.applenum = 0;
                } else {
                    this.applenum--;
                    this.appletotal = this.applenum * 3;
                }
            },

            bananaadd: function () {
                this.banananum++;
                this.bananatotal = this.banananum * 5;
            },
            bananareduce() {
                if (this.banananum == 0) {
                    this.banananum = 0;
                } else {
                    this.banananum--;
                    this.bananatotal = this.banananum * 5;
                }
            },

            pearadd: function () {
                this.pearnum++;
                this.peartotal = this.pearnum * 4;
            },
            pearreduce() {
                if (this.pearnum == 0) {
                    this.pearnum = 0;
                } else {
                    this.pearnum--;
                    this.peartotal = this.pearnum * 4;
                }
            },


        },

        computed: {
           price: function () {
                return this.appletotal+this.peartotal+this.bananatotal;
               // return Number.parseFloat(this.applenum)*3;
            }
        }
    });
</script>
</body>
</html>